﻿using UnityEngine;
using System.Collections;

public class WeaponController : MonoBehaviour 
{
    public GameObject shot;
    public Transform ShotSpawn;
    public float FireRate;
    public float delay;

    private GameController _GameController;

    void Start()
    {
        GameObject GameControllerObject = GameObject.FindWithTag("GameController");
        if (GameControllerObject != null)
        {
            _GameController = GameControllerObject.GetComponent<GameController>();
        }

        InvokeRepeating("Fire", delay, FireRate);
    }

    void Fire()
    {
        if (_GameController.CheckState() == false)
        {
            Instantiate(shot, ShotSpawn.position, ShotSpawn.rotation);
            GetComponent<AudioSource>().Play();
        }
    }
}
